﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;

namespace NutriStat
{
    class NutriMenuItem
    {
        #region Data
        #region Protected Data
        #endregion Protected Data

        #region Private Data
        string fileName;
        string compactFileName;
        string tableName;
        #endregion Private Data

        #region Internal Data
        #endregion Internal Data
        #endregion Data

        #region Constructors
        #endregion

        #region Properties
        #region Public Properties
        /// <summary>
        /// Gets the file name
        /// </summary>
        public string FileName
        {
            get
            {
                return fileName;
            }
            set
            {
                fileName = value;
            }
        }

        /// <summary>
        /// Gets the file name
        /// </summary>
        public string CompactFileName
        {
            get
            {
                return compactFileName;
            }
            set
            {
                compactFileName = value;
            }
        }

        /// <summary>
        /// Gets the table name
        /// </summary>
        public string TableName
        {
            get
            {
                return tableName;
            }
            set
            {
                tableName = value;
            }
        }
        #endregion Public Properties

        #region Protected Properties
        #endregion Protected Properties

        #region Private Properties
        #endregion Private Properties
        #endregion Properties
      
        #region Constructors
        /// <summary>
        /// A constructor for the menu item class
        /// </summary>
        public NutriMenuItem(string table, string file)
        {
            FileName = file;
            CompactFileName = file;
            TableName = table;

            FormatLongFileName();
        }

        /// <summary>
        /// A constructor for the menu item class
        /// </summary>
        public NutriMenuItem(string fullPath)
        {            
            int separator = fullPath.IndexOf("::");
            FileName = fullPath.Substring(0, separator);
            TableName = fullPath.Replace(FileName, string.Empty);
            TableName = TableName.Replace("::", string.Empty);
            CompactFileName = FileName;

            FormatLongFileName();
        }
        #endregion Constructors

        #region Methods
        public override string ToString()
        {
            //return base.ToString();
            return CompactFileName;
        }

        private void FormatLongFileName()
        {
            if (FileName.Length > 32)
            {
                int middle = FileName.Length / 2;
                int start = middle - FileName.Length / 4;
                int length = FileName.Length / 4;

                string midsection = FileName.Substring(start, length);
                CompactFileName = CompactFileName.Replace(midsection, SharedStrings.ELIPSIS);
            }
        }
        #endregion Methods


    }
}
